﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Threading;
using System.Windows.Forms;
using CD2WebAudio3UI.Forms;

namespace CD2WebAudio3UI
{
    public class TheApp
    {
        public static string Title = "CD to Web Audio 3";
        public static bool Cancel = false;

        public static void Run(string[] args)
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;
            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
            System.Windows.Forms.Application.EnableVisualStyles();

            System.Windows.Forms.Application.Run(new frmMain());
        }

        static void MyHandler(object sender, UnhandledExceptionEventArgs args)
        {
            Exception e = (Exception)args.ExceptionObject;

            // build the message
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(e.Message);
            sb.AppendLine("\nDo you want to see the detail?");

            // show the simple message
            DialogResult mbr = MessageBox.Show( sb.ToString(), "CD to Web Audio 3", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button2);

            // show the detailed message
            if (mbr == DialogResult.Yes)
            {
                MessageBox.Show(e.ToString(), "CD to Web Audio 3", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        /// <summary>
        /// Loops through DoEvents for a number of seconds.
        /// </summary>
        /// <param name="pSeconds">Seconds to wait</param>
        public static void Wait(int pSeconds)
        {
            DateTime dt = DateTime.Now;
            while (dt.AddMilliseconds(pSeconds * 1000) > DateTime.Now)
            {
                Application.DoEvents();
            }
        }
    }
}
